import request from '../service/service';
import * as project from './project';
import * as bimface from './bimface';
import * as security from './security';
import * as device from './device';
import * as personnel from './personnel';
import * as technologyManage from './technologyManage';
import * as quality from './quality';
import * as comprehensive from './comprehensive';
import * as progress from './progress';
import * as weather from './weather';
import * as material from './material';
import * as message from './message';
import * as user from './user';
import * as role from './role';
import * as org from './org';
import * as environment from './environment';

/**
 * 获取用户登录信息
 * @param data {Object} 请求参数 { user_id：'用户id', password: '' }
 */
async function login(data) {
  return await request({
    protocol: 'login/login',
    options: data
  });
}

/**
 * 退出登录
 * @param data {Object} 请求参数 { user_id：'用户id' }
 */
async function logout(data) {
  return await request({
    protocol: 'login/logout',
    options: data
  });
}

/**
 * 查询一个项目所有监控摄像头（萤石云监控视频接口）
 * @param data {Object} 请求参数
 * "project_name":"径山寺宾馆项目"//必填，项目名
 */
async function getameraList(data) {
  return await request({
    protocol: 'camera/get_camera_list_by_project',
    options: data
  });
}

/**
 * 文件上传
 * @param data {Object} 请求参数
 * "file":""  {formData} 必填，文件对象
 */
async function fileUpload(data) {
  return await request({
    protocol: '/bus/file/upload',
    options: data,
    method: 'formData',
    requestConfig: {
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
      }
    }
  });
}

/**
 * 文件删除
 * @param data {Object} 请求参数
 * "filePath":""  {string} 必填，文件路径
 * @param  config {?Object}
 */
async function fileDelete(data, config = {}) {
  return await request({
    protocol: '/bus/file/delete?filePath=' + data.filePath,
    ...config
  });
}

/**
 * 根据用户ID/名称/电话搜索用户
 */
export function findUserList(data) {
  return request({
    protocol: 'user/findUserList',
    options: data,
    method: 'get',
  });
}

// 请求方法
export default {
  login,
  logout,
  fileUpload,
  fileDelete,
  getameraList,
  findUserList,
  ...project,
  ...bimface,
  ...security,
  ...device,
  ...personnel,
  ...technologyManage,
  ...quality,
  ...comprehensive,
  ...progress,
  ...weather,
  ...material,
  ...message,
  ...user,
  ...role,
  ...org,
  ...environment
};
